Skip to content

Conversation

@MuriloFP
Copy link
Contributor

@MuriloFP MuriloFP commented Jul 24, 2025

Related GitHub Issue

Closes: #4127

Roo Code Task Context (Optional)

No Roo Code task context for this PR

Description

This PR implements a 3-message synthetic context generation pattern to resolve focus and performance issues when file mentions (@filename) are used in the first user message.

Key implementation details:

  • Added extractFileMentions utility to detect and extract file paths from @ mentions
  • Modified Task.initiateTaskLoop to intercept first messages containing file mentions
  • Created handleFirstMessageWithFileMentions method that generates the synthetic message pattern:
    1. Original user message (stored in task history without embedded content)
    2. Synthetic assistant message with <read_file> tool calls
    3. User message with the actual file contents
  • The task history (say method) only sees the clean original message, preventing UI performance degradation
  • The API conversation gets the proper context in the correct order, preventing model focus issues

Test Procedure

Automated Testing:

  1. Added unit tests for extractFileMentions utility:
    cd src && npx vitest run core/mentions/__tests__/extractFileMentions.spec.ts
  2. Added integration tests for Task class to verify the 3-message pattern generation:
    cd src && npx vitest run core/task/__tests__/Task.spec.ts

Manual Testing:

  1. Build and run the extension
  2. Start a new task with a file mention: @src/index.ts explain this file
  3. Verify that:
    • The task history shows only the original message without embedded content
    • The model receives the file content in the proper context order
    • The UI remains responsive even with large files

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

No UI changes in this PR

Documentation Updates

  • No documentation updates are required.

Additional Notes

This implementation ensures backward compatibility - tasks without file mentions in the first message continue to work exactly as before. The synthetic message pattern is only generated when needed.

Get in Touch

Discord username not provided


Important

Introduces a synthetic message pattern to handle file mentions in the first message, improving focus and performance.

  • Behavior:
    • Implements a 3-message synthetic context pattern in Task.ts to handle file mentions in the first message.
    • Adds extractFileMentions utility in extractFileMentions.ts to detect file paths from @ mentions.
    • Modifies Task.initiateTaskLoop to intercept first messages with file mentions.
    • Introduces handleFirstMessageWithFileMentions in synthetic-messages.ts to generate synthetic messages.
  • Testing:
    • Adds unit tests for extractFileMentions in extractFileMentions.spec.ts.
    • Adds integration tests for Task class in Task.spec.ts to verify synthetic message pattern.
  • Misc:
    • Updates parseMentions in index.ts to simplify file mention handling.

This description was created by Ellipsis for c59edca. You can customize this summary. It will automatically update as commits are pushed.

MuriloFP and others added 26 commits July 3, 2025 15:26
… message (RooCodeInc#4127)

- Implement 3-message synthetic context generation pattern
- Original user message stored without embedded file content in task history
- Synthetic assistant message with read_file tool calls generated
- File contents processed and added as separate user response
- Prevents model focus degradation and UI performance issues
- Add comprehensive tests for the new functionality
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jul 24, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 24, 2025
- Remove 'processed:' prefix from parseMentions mock
- Update test expectations to match new behavior
- Fix processUserContentMentions mock usage
Copy link
Contributor

@KJ7LNW KJ7LNW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in addition to the comment below:

  1. we no longer need to modify the first message since you are injecting it in the rest of the body.

I do not remember where that is somewhere it changes @mention to @mention (see file below) or something like that.

this pull request makes it possible for the first message to arrive and modified.

  1. it was not clear to me whether or not the task.ts changes trigger to start after modifying the context: it would be a good idea to manually verify that when you create the mention that the task loads the files and continues without user intervention

@MuriloFP MuriloFP marked this pull request as draft July 24, 2025 20:51
MuriloFP added 2 commits July 24, 2025 18:19
- Fixed failing unit tests by properly mocking extractFileMentions and hasFileMentions
- Removed 'see below for file content' text from file mentions as requested in PR review
- Updated all related test expectations to match the new behavior
- Ensured task continues automatically after synthetic message handling
- Moved shouldUseSyntheticMessages, handleFirstMessageWithFileMentions, and createSyntheticReadFileMessage to new synthetic-messages.ts module
- Made addToApiConversationHistory public to allow access from the new module
- Updated imports and function calls in Task.ts
- Addresses PR feedback about Task.ts getting too large
@MuriloFP MuriloFP marked this pull request as ready for review July 24, 2025 21:55
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 24, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jul 24, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jul 29, 2025
- Modified createSyntheticReadFileMessage to batch files in groups of 5
- Updated tests to verify single read_file call with multiple files
- Added test for batching behavior when more than 5 files are mentioned
- This improves efficiency by reducing the number of tool calls needed
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 29, 2025
@MuriloFP
Copy link
Contributor Author

Changes Made

I've updated the synthetic message generation to use the multi-file read capability of the read_file tool:

Key Changes:

  1. **Modified ** to batch files in groups of 5 (the maximum allowed by the read_file tool)
  2. Updated tests to verify that multiple files are now read in a single tool call instead of separate calls
  3. Added new test for batching behavior when more than 5 files are mentioned

Benefits:

  • More efficient handling of multiple file mentions
  • Reduces the number of tool calls needed
  • Aligns with how the read_file tool is designed to work (supporting up to 5 files per call)

Example:

When a user mentions 2 files like @file1.ts @file2.ts, instead of creating:

<read_file>...</read_file>
<read_file>...</read_file>

We now create:

<read_file>
<args>
  <file>
    <path>file1.ts</path>
  </file>
  <file>
    <path>file2.ts</path>
  </file>
</args>
</read_file>

All tests are passing ✅

@MuriloFP
Copy link
Contributor Author

Changes Made

I've updated the synthetic message generation to use the multi-file read capability of the read_file tool:

Key Changes:

  1. Modified createSyntheticReadFileMessage to batch files in groups of 5 (the maximum allowed by the read_file tool)
  2. Updated tests to verify that multiple files are now read in a single tool call instead of separate calls
  3. Added new test for batching behavior when more than 5 files are mentioned

Benefits:

  • More efficient handling of multiple file mentions
  • Reduces the number of tool calls needed
  • Aligns with how the read_file tool is designed to work (supporting up to 5 files per call)

Example:

When a user mentions 2 files like @file1.ts @file2.ts, instead of creating:

<read_file>...</read_file>
<read_file>...</read_file>

We now create:

<read_file>
<args>
  <file>
    <path>file1.ts</path>
  </file>
  <file>
    <path>file2.ts</path>
  </file>
</args>
</read_file>

All tests are passing ✅

@MuriloFP MuriloFP moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Jul 30, 2025
@daniel-lxs
Copy link
Member

This looks good! I only noticed 1 issue but that's probably because it's such a new feature:

When I mention an image the generated message tells Roo that it can't read images with the read_file tool, which might confuse the model because right now the read_file tool is able to read images, this might also be happening with other file types like .pdf.

It would be great if we can re utilize the logic on the readFileTool.ts file rather than implementing it again.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jul 31, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 23, 2025
@github-project-automation github-project-automation bot moved this from PR [Changes Requested] to Done in Roo Code Roadmap Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working PR - Changes Requested size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Focus and Performance Issues: File Contents in First Message

4 participants